'use strict';

const getBanners = require('./get-banners');
const addBanner = require('./add-banner');
const updateBanner = require('./update-banner');
const deleteBanner = require('./delete-banner');
const batchOperate = require('./batch-operate');
const getBannerDetail = require('./get-banner-detail');

exports.main = async (event, context) => {
  const { action, data } = event;
  
  try {
    switch (action) {
      case 'get-banners':
        return await getBanners.main(event, context);
      case 'add-banner':
        return await addBanner.main(event, context);
      case 'update-banner':
        return await updateBanner.main(event, context);
      case 'delete-banner':
        return await deleteBanner.main(event, context);
      case 'batch-operate':
        return await batchOperate.main(event, context);
      case 'get-banner-detail':
        return await getBannerDetail.main(event, context);
      default:
        return {
          code: 400,
          message: '未知的操作类型',
          data: null
        };
    }
  } catch (error) {
    console.error('云函数执行错误:', error);
    return {
      code: 500,
      message: '服务器内部错误',
      data: null
    };
  }
};